<template>
  <div>
    <!--面包屑导航区-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--card卡片-->
    <el-card class="box-card">
      <!--搜索框-->
      <el-input placeholder="请输入内容" v-model="inputText"
                class="input-with-select">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!--table表格-->
      <el-table :data="orderList" border stripe style="width: 100%">
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="200px"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="props">
            <el-tag type="danger" v-if="props.row.pay_status === '0'">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="props">{{props.row.create_time | dateFormat}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <el-button size="mini" type="primary" class="el-icon-edit" @click="editHandle"></el-button>
          <el-button size="mini" type="success" class="el-icon-location" @click="showProgressBox"></el-button>
        </el-table-column>
      </el-table>
      <!--分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="getOrdersQuery.pagenum"
        :page-sizes="[10,20,30,40]"
        :page-size="getOrdersQuery.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
    <!---->
    <!---->
    <!---->
    <!--编辑-->
    <el-dialog title="修改地址"
      :visible.sync="editDialogVisible"
      width="50%" @close="addressClose">
      <el-form :model="addressForm" :rules="addressRules" ref="addressRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader v-model="addressForm.address1"
            :options="citydata"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input class="address2" v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editAddress">确 定</el-button>
      </span>
    </el-dialog>
    <!---->
    <!---->
    <!---->
    <!--编辑-->
    <el-dialog title="物流进度"
               :visible.sync="progressVisible"
               width="50%">
    </el-dialog>
  </div>
</template>

<script>
import citydata from './citydata'
export default {
  data: function () {
    return {
      getOrdersQuery: {
        query: '',
        pagenum: 1,
        pagesize: 10,
        consignee_addr: ''
      },
      total: 0,
      inputText: '',
      orderList: [],
      // 监听隐藏、弹出修改地址弹框
      editDialogVisible: false,
      // 修改地址的form表单
      addressForm: {
        address1: '',
        address2: ''
      },
      // 修改地址的form表单验证规则
      addressRules: {
        address1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      // 城市信息
      citydata: citydata,
      progressVisible: false,
      progressInfo: []
    }
  },
  created: function () {
    this.getOrders()
  },
  methods: {
    getOrders: async function () {
      var { data: res } = await this.$http.get('orders', { params: this.getOrdersQuery })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表列表')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 每页条数
    handleSizeChange(val) {
      this.getOrdersQuery.pagesize = val
      this.getOrders()
    },
    // 当前页
    handleCurrentChange(val) {
      this.getOrdersQuery.pagenum = val
      this.getOrders()
    },
    // 修改地址
    editHandle: function () {
      this.editDialogVisible = true
    },
    // 级联选择器
    handleChange(value) {
      console.log(value)
    },
    addressClose: function () {
      this.$refs.addressRef.resetFields()
    },
    editAddress: function () {
      console.log(this.addressForm)
    },
    showProgressBox: async function () {
      this.progressVisible = true
      // 后台接口有问题，无法获取数据
      var { data: res } = await this.$http.get('kuaidi/1106975712662')
      console.log(res)
      if (res.meta.status !== 200) {
        return this.$message.error('获取物流信息失败')
      }
      this.$message.success('获取物流信息成功')
      this.progressInfo = res.data
    }
  }
}
</script>

<style lang="less" scoped>
  .el-input{
    width: 300px;
  }
  .el-cascader{
    width: 100%;
  }
  .address2{
    width: 100%;
  }
</style>
